<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
    <div id="app" style="margin: 100px;">
    <parent></parent>
    </div>

    <template id="par">
        <div>
            <h1>{{parentMsg}}:{{message}}</h1>
            <child1 @change="getVal"></child1>
        </div>
    </template>

    <template id="c1">
        <div>
            <button @click="fn">点击传值父组件</button>
            <p>准备传递的数据:{{cMsg1}}</p>
        </div>
    </template>
</body>
<script type="text/javascript">
var vm=new Vue({
    el:"#app",
    data:{

    },
    components:{
        "parent":{
            template:"#par",
            data(){
                return{

                    parentMsg:"父组件接收信息",
                    message:""
                }
            },
            methods: {
                getVal:function(val){
                    //Val:代表传递过来的值
                    this.message=val;
                    console.log("接受的信息为:"+this.message)
                }
            },
            components:{
              "child1":{
            template:"#c1",
            data(){
                return{
                 cMsg1:"1000"
                }
            },
            methods: {
                fn:function(){
                    //自定义事件
                    this.$emit("change",this.cMsg1);
                }
             }
           }
          }
        }
       
    }
   
})
</script>
</html>